package com.wgj.android.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.TextView;

import com.jiaai.xui.utils.http.HttpCallBack;
import com.jiaai.xui.utils.http.XHttp;
import com.jiaai.xui.utils.imageload.XImage;
import com.jiaai.xui.view.widget.XLoadingDialog;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;
import com.wgj.android.entity.Member;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.utils.CacheUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/14.
 */

public class EditNickNameActivity extends AppCompatActivity {
    @BindView(R.id.nickName)
    EditText editText;
    private Member member;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.edit_user_nick_naem_activity);
        ButterKnife.bind(this);
        member= CacheUtils.getMember();
        editText.setText(member.getM_nick());
    }

    @OnClick(R.id.sumbit)
    public void onSumbitClick(){
        if(editText.length()<=0){
            XToast.error("请输入昵称");
            return;
        }
        XLoadingDialog.with(EditNickNameActivity.this).setMessage("正在保存");
        Map<String,Object> params=new HashMap<>();
        params.put("mId",member.getM_id());
        params.put("mNick",editText.getText().toString());
        XHttp.obtain().post(WGJAPI.UPDATE_MEMBER_API, params, new HttpCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                member.setM_nick(editText.getText().toString());
                XLoadingDialog.with(EditNickNameActivity.this).dismiss();
                try {
                    CacheUtils.setMember(member);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                XToast.success("修改成功",3000);
                finish();
            }
            @Override
            public void onFailed(int i, String s, boolean b) {
                XToast.error("修改失败");
                XLoadingDialog.with(EditNickNameActivity.this).dismiss();
            }
        });
    }

}
